<template>
  <div class="layui-layout layui-layout-admin">
    <div class="adminnav1">
      <Pagetop></Pagetop>
    </div>
    <div class="adminnav2">
      <Secondnav urlname="homepage"></Secondnav>
    </div>

    <!-- 主体内容 -->
    <div class="layui-body kedou-admin" id="LAY_app_body app">
      <div class="layadmin-tabsbody-item layui-show">
        <div class="pagelist">
          <div class="layui-card-body">
            <ul class="layui-tab-title">
              <li class="layui-this"><router-link to="/gradelist">开户费配赠设置</router-link></li>
              <li><router-link to="/khflist">开户费基础设置</router-link></li>
            </ul>
          </div>
          <div class="pagetop">
            <Search :seadate="searchArr"></Search>
          </div>
          <div class="layui-card-body">
            <div class="buttop">
              <button type="button" class="layui-btn layui-btn-normal" @click="addData">添加会员等级开户费送</button>
              <button type="button" class="layui-btn" @click="setData">关联区域费用设置</button>
              <button type="button" class="layui-btn  layui-btn-warm" @click="setsqData">关联商圈费用设置</button>
            </div>
            <Tables
              :fdate="pdate"
              :result="res"
              height="430"
              :totalCount="totalRows"
              :pageNumber="curindex"
              :fbtn="btn"
            ></Tables>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Pagetop from "../../common/pagetop.vue";
import Secondnav from "../../common/secondnav.vue";
import Tables from "../../common/tables.vue";
import Search from "../../common/search.vue";
export default {
  name: "gradelist",
  components: { Pagetop, Secondnav, Tables, Search },
  data() {
    return {
      pdate: [], //表头
      res: "", //内容
      totalRows: "", //总数量
      curindex: 1, //页数
      btn: [], //按钮
      searchArr: [], //搜索
      isShow: false,
      seapram: "",
      type: localStorage.getItem("type"),
    };
  },
  mounted() {
    this.getdate();
    this.getsearch();
  },
  methods: {
    getdate: function () {
      var _this = this;
      var url = "/profit/aapi/v1.9/grade-type-setting";
      if (_this.seapram) {
        var dates = {
          size: pageSize,
          page: _this.curindex,
          //sort:'createAt,DESC',
          //'status.equals':'ENABLE'
        };
        var res = _this.seapram;
        for (var i = 0; i < res.length; i++) {
          dates[res[i].key + ".equals"] = res[i].val;
        }
      } else {
        var dates = {
          size: pageSize,
          page: _this.curindex,
          //sort:'createAt,DESC',
          //'status.equals':'ENABLE'
        };
      }
      //alert(url+"//"+JSON.stringify(dates))
      ajaxRequest(url, "GET", "json", dates, function (ret, err) {
        //alert(url+"//"+JSON.stringify(ret))
        var arr = [];
        arr[0] = [
          { field: "id", title: "ID" },
          { field: "gradeSetting", title: "会员等级", 
          templet: function (d) {
              return d.gradeSetting.name;
            }, },
          {
            field: "balanceZxzc",
            title: "WDT(专项资产)配赠",
            templet: function (d) {
              return d.balanceZxzc / 100;
            },
          },
          {
            field: "balanceUc",
            title: "配赠类型",
            templet: function (d) {
              if(d.type=='BOOK'){
              	return '开户费'
              }
              else if(d.type=='REGION'){
              	return '绑定区域'
              }
              else{
              	return '绑定商圈'
              }
            },
          },
          {
            field: "balanceUc",
            title: "UC配赠",
            templet: function (d) {
              return d.balanceUc / 100;
            },
          },
          {
            field: "balanceUc",
            title: "WUC配赠",
            templet: function (d) {
              return d.balanceWuc / 100;
            },
          },
          {
            field: "balanceXfgf",
            title: "消费工分",
            templet: function (d) {
              return d.balanceXfgf / 100;
            },
          },
          {
            field: "balanceCreditUc",
            title: "授信",
            templet: function (d) {
              return d.balanceCreditUc / 100;
            },
          },
          { field: "redFrequency", title: "红包次数" },
          { field: "stackRebate", title: "共享链上易栈返点比例(%)" },
          { field: "villageRebate", title: "共享链上易庄返点比例(%)" },
          { field: "status", title: "状态",templet:function (d) {
              if(d.status == 'ENABLE') return "激活"
              else return "禁用" 
            } },
          {
            field: "right",
            title: "操作",
            width: "120",
            fixed: "right",
            templet: function (d) {
              var str =
                '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>';
             if(d.status=='ENABLE'){
		         	str=str+'<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="enable">禁用</a>';
		         }
		         else{
		         	str=str+'<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="enable">启用</a>';
		         }
              return str;
            },
          },
        ];
        _this.pdate = arr;
        _this.res = ret.data.list; //res1;
        _this.totalRows = ret.data.totalRows;
        _this.curindex = ret.data.page + 1;
      });
    },
    getsearch: function () {
      var arr = [{ field: "id", title: "ID", type: "input" }];
      this.searchArr = arr;
    },
    page: function (index, obj) {
      //alert(JSON,stringify(obj))
      this.curindex = index;
      this.getdate();
    },
    sousuo: function (pram) {
      //alert(JSON.stringify(pram))
      this.seapram = pram;
      this.res = "";
      this.totalRows = "";
      this.curindex = "";
      this.getdate();
    },
    addData: function () {
      var _this = this;
      layer.open({
        type: 2,
        title: "新增会员等级开户费送信息",
        content: baseurl + "/gradeadd",
        area: _this.screens() < 2 ? ["80%", "65%"] : ["800px", "650px"],
      });
    },
    setData: function (data) {
      var _this = this;
      layer.open({
        type: 2,
        title: "关联区域费用设置",
        content: baseurl + "/feeset",
        area: _this.screens() < 2 ?["80%", "65%"] : ["800px", "650px"],
        success: function (layero, index) {
          var iframeWin = window[layero.find("iframe")[0]["name"]];
          iframeWin.getdates(data);
        },
      });
    },
    setsqData: function (data) {
      var _this = this;
      layer.open({
        type: 2,
        title: "关联商圈费用设置",
        content: baseurl + "/feeset",
        area: _this.screens() < 2 ?["80%", "65%"] : ["800px", "650px"],
        success: function (layero, index) {
          var iframeWin = window[layero.find("iframe")[0]["name"]];
          var obj=data;
          obj.byfrom='sq'
          iframeWin.getdates(obj);
        },
      });
    },
    editInfo: function (data) {
      var _this = this;
      layer.open({
        type: 2,
        title: "编辑会员等级开户费送信息",
        content: baseurl + "/gradeadd",
        area: _this.screens() < 2 ? ["80%", "65%"] : ["800px", "650px"],
        success: function (layero, index) {
          var iframeWin = window[layero.find("iframe")[0]["name"]];
          iframeWin.getdates(data);
        },
      });
    },
    enableInfo:function(data){
		var _this = this;
		if(data.status=='ENABLE'){
			var status="DISABLE"
		}
		else{
			var status="ENABLE"
		}
		var url = "/profit/aapi/v1.9/grade-type-setting/"+data.id+"/"+status;
		ajaxRequest(url,'PUT','json','',function(ret,err){
			layer.msg("操作成功");
			setTimeout(function(){
			  	_this.getdate();
	      },1000)
		})
	},
    screens: function () {
      return screen();
    },
  },
  updated: function () {
    this.isShow = true;
    layui.use("form", function () {
      var form = layui.form;
      form.render();
    });
  },
};
</script>
<style scoped>
/**/
</style>